package com.yoso.thread.call;

import com.yoso.domain.User;
import com.yoso.thread.MyThreadPool;
import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;

/**
 * @author shizejin
 * @date 2022/4/2
 * @description:
 */
@Slf4j
public class Test2 {
    public static void main(String[] args) {
        ExecutorService executorService = MyThreadPool.getInstance();
        User user = new User();
        user.setId("101");
        Future<String> future =  executorService.submit(()->{
            log.warn("future==start");
            Thread.sleep(6000);
            user.setAge(10);
            return user.toString();
        });
        User user2 = new User();
        user2.setId("201");
        Future<String> future2 =  executorService.submit(()->{
            log.warn("future2==start");
            Thread.sleep(2000);
            user2.setAge(20);
            return user2.toString();
        });


        try {
            System.out.println("=======================");
            String s1 = future2.get();
            System.out.println(s1);
            String s = future.get();
            System.out.println(s);

        } catch (InterruptedException | ExecutionException e) {
            e.printStackTrace();
        }
    }
}
